<template>
  <div class="page">
    <!-- 搜索区域 开始 -->
    <div class="el_card_box">
      <el-form :inline="true" size="small" :model="formInline" class="search_form">
        <el-form-item label="城市：">
          <el-select v-model="formInline.city" filterable @change="getHospital">
            <el-option v-for="(item, index) in cityList" :key="index" :label="item.name" :value="item.code"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="医院：">
          <el-select v-model="formInline.hospital" filterable>
            <el-option v-for="(item, index) in hospitalList" :key="index" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="医生：">
          <el-select v-model="formInline.city1">
            <el-option label="深圳" value="1"></el-option>
            <el-option label="湖南" value="2"></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="关键词：">
          <el-input v-model="formInline.doctor" placeholder="请输入医生姓名/电话"></el-input>
        </el-form-item>
      </el-form>
      <div class="search_btn_box">
        <el-button type="primary" size="small" @click="onSearch">筛选</el-button>
        <el-button type="default" size="small" @click="rest">清空筛选</el-button>
      </div>
    </div>
    <!-- 搜索区域 end -->

    <!-- 表格 开始 -->
    <div class="table_box">
      <!-- 操作区域 开始 -->
      <div class="action_box">
        <!-- <el-button type="primary" size="small" @click="addDoctor()">新增医生</el-button> -->
        <auth-button uid="1060203" type="primary" size="small" @click.native="addDoctor()">新增医生</auth-button>
      </div>
      <!-- 操作区域 end -->

      <el-table ref="elTable" class="el_table" size="small" :data="tableData">
        <el-table-column prop="channelName" label="医生信息">
          <template slot-scope="{row}">
            <tab-doctor :user="row" :hidden="true" url="doctor/add"></tab-doctor>
          </template>
        </el-table-column>
        <el-table-column prop="personalTitle" label="称号/职称" show-overflow-tooltip />
        <el-table-column prop="expertProject" label="擅长项目" show-overflow-tooltip />
        <el-table-column prop="workYears" label="从业年限" show-overflow-tooltip />
        <el-table-column prop="practiceLicenseNo" label="医生海报" show-overflow-tooltip width="80px">
          <template slot-scope="{row}">
            <el-link type="primary" class="el_link" :underline="false" @click="previewImage(row)" v-if="row.poster">查看</el-link>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="practiceLicenseNo" label="职业编号" show-overflow-tooltip /> -->
        <!-- <el-table-column prop="address" label="操作" width="200px" align="center">
          <template slot-scope="{row}">
             <auth-link uid="1060204" type="primary" class="el_link" :underline="false" :id="row.id" @click.native="addDoctor(row.id)">编辑</auth-link>
            <auth-link uid="1060205" type="primary" class="el_link" :underline="false" :id="row.id" @click.native="remove(row)">删除</auth-link>
          </template>
        </el-table-column> -->
      </el-table>
      <div class="pagination_list">
        <el-pagination background layout="sizes, total,prev, pager, next, jumper" :total="pageTotal" :page-size="pageSize" :page-sizes="pageSizes" :current-page.sync="pageNumber" @current-change="getList" @size-change="changePageSize" />
      </div>
    </div>
    <!-- 表格 end -->

    <!-- 收款变动 开始 -->
    <!-- <glsx-dialog :show="showDialog" :title="dialogTitle" width="80%" @close="closeDialog('showDialog')">
    </glsx-dialog> -->
    <!-- 收款变动 end -->

  </div>
</template>

<script>
import { GETCITYOPTIONS } from "@/http/system";
import { showToast, showModal, deepClone } from "@/common/util";
import GlsxDialog from "@/components/Dialog/index";
import TabDoctor from "@/components/doctor";
import { GETDOCTORSEARCH, DELETEDOCTORINFO } from "@/http/doctor";
import { BASEURL,GETHOSPITALOPTIONS } from "@/http/hospital";
import { api as viewerApi } from "v-viewer";
import "viewerjs/dist/viewer.css";
export default {
  name: "BookPage",
  props: {
    status: {
      type: [String, Number],
      default: "",
    },
  },
  components: {
    GlsxDialog,
    TabDoctor,
  },
  data() {
    return {
      formInline: {},
      tableData: [],
      pageTotal: 0,
      pageNumber: 1,
      pageSizes: [10, 20, 50, 100],
      pageSize: 20,
      orderTime: [],
      orderTime2: [],
      showDialog: false,
      loading: false,
      dialogTitle: "新增医院",
      cityList: [],
      hospitalList: []
    };
  },
  mounted() {
    this.getList();
    this.getCity();
    this.getHospital()
  },
  methods: {
    /** 重置 */
    rest() {
      this.formInline = {};
      this.orderTime = [];
      this.getList();
    },

    /** 每页展示 */
    changePageSize(e) {
      this.pageSize = e;
      this.getList();
      this.getHospital()
    },

    /** 获取参数 */
    getParams() {
      let oParams = JSON.parse(JSON.stringify(this.formInline));
      let n = this.orderTime;

      if (n && n.length > 0) {
        oParams.sDate = n[0];
        oParams.eDate = n[1];
      }

      oParams.pageNumber = this.pageNumber;
      oParams.pageSize = this.pageSize;
      return oParams;
    },

    /** 获取列表 */
    getList() {
      let _this = this;
      let oParams = this.getParams();
      GETDOCTORSEARCH(oParams).then((res) => {
        let obj = res.data || {};
        _this.tableData = obj.list || [];
        _this.pageTotal = obj.totalElements;
      });
    },

    // 打开弹框
    openDialog(id, title) {
      this[id || "showDialog"] = true;
      this.dialogTitle = title;
    },

    // 关闭弹框
    closeDialog(id) {
      this[id || "showDialog"] = false;
    },

    // 新增医院
    addDoctor(id) {
      this.$router.push({ name: "addDoctor", query: { id: id } });
    },

    // 删除医生
    remove(row) {
      let _this = this;
      showModal({
        message: `确认删除${row.name}医生吗？`,
        showCancelButton: true,
        success: function () {
          let oParams = {};
          oParams.id = row.id;
          DELETEDOCTORINFO(oParams).then((res) => {
            if (res.code == 200) {
              showToast({
                message: "删除成功",
                type: "success",
              });
              _this.getList();
            }
          });
        },
      });
    },

    // 获取所有城市
    getCity() {
      GETCITYOPTIONS().then((res) => {
        this.cityList = res.data || [];
      });
    },

    // 获取所有医院
    getHospital(code) {
      let oParams = {};
      oParams.city = code;
      if (this.formInline.hospital) {
        delete this.formInline.hospital;
      }
      GETHOSPITALOPTIONS(oParams).then((res) => {
        this.hospitalList = res.data || [];
      });
    },

    // 图片预览
    previewImage(row) {
      this.imageList = [BASEURL + row.poster];
      viewerApi({
        images: this.imageList,
        options: {
          zIndex: 99999,
        },
      });
    },
    
    // 搜索
    onSearch(){
      this.pageNumber = 1;
      this.getList()
    }

  },
};
</script>

<style lang="scss" scoped>
@import "@/assets/style/customer/index.scss";
</style>
